# -*- coding: utf-8 -*-
# @Time : 2021/10/29 16:58
# @Author : Ming
# @FileName: RNN.py
# @Software: PyCharm

import torch

# https://blog.csdn.net/m0_46326454/article/details/115187831 学习参考

# 自定义变量
batch_size = 1      #批量数
seq_len = 3         #序列长度，也就是有多少个序列，x1,x2,x3
input_size = 4      #输入张量（向量）的维度
hidden_size = 2     #中间隐层张量的维度
num_layers = 1      #RNN层数

# 三个参数，多了一个num_layers，来表示循环神经网络层数
cell = torch.nn.RNN(input_size=input_size, hidden_size=hidden_size
                    , num_layers=num_layers)

# (seq_len, batch_size, input_size)
inputs = torch.randn(seq_len, batch_size, input_size)
hidden = torch.zeros(num_layers, batch_size, hidden_size)

# out承接了seq_len所有对应的输出
out, hidden = cell(inputs, hidden)

print('Output size', out.shape)
print('Output: ', out)
print('Hidden size', hidden.shape)
print('Hidden: ', hidden)


